<?php

class Invoice extends Zend_Db_Table
{
    protected $_name = 'invoice';
    
    public function getInvoice($id)
    {
        $group = $this->fetchRow('id='.$id);
        return $group;
    }
    
    public function getInfo($id)
    {
        $group = $this->fetchRow('id='.$id);
        return $group->id.'. '.$group->riskdate.' '.$group->appointment;
    }
    
    public function getLastInvoice($user_id,$start,$end){
        $select = $this->getAdapter(); 
        $query = 'SELECT invoice.riskdate
                FROM invoice
                WHERE user_id='.(int)$user_id.'
                AND deleted!=1
                AND riskdate >= "'.$start.'"
                AND riskdate <= "'.$end.'"
                ORDER BY riskdate DESC
                LIMIT 1';
         $prepare = $select->query($query);
         $result = $prepare->fetchAll(Zend_Db::FETCH_OBJ);
         if(count($result)>0) return $result[0]->riskdate;
         else return 'Не найдено';
    }
}